<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 目的：假设a、b不同域，现在需要拿到b的数据 -->
    <!-- <iframe src="b.html" frameborder="0"></iframe> -->
    <button onclick="exec_click()">点我拿到b页面的数据</button>
    <script>
        function exec_click() {
            let ifr = document.createElement('iframe')
            let flag = false
            ifr.style.display = 'none'
            ifr.onload = function() {
                if(flag) {
                    console.log('执行');
                    let data = ifr.contentWindow.name
                    console.log(data)
                    ifr.contentWindow.close()
                    document.body.removeChild(ifr)
                } else {
                    ifr.contentWindow.name = "{a: '我是b的数据'}"
                    ifr.src = 'c.html'
                    flag = true
                }
            }
            ifr.src = 'b.html'
            document.body.appendChild(ifr);
        }
    </script>
</body>
</html>